/*
 * This is the player class.
 */

package block;

import java.awt.Rectangle;
import java.awt.event.KeyEvent;
import java.util.ArrayList;

/*
 * This class defines the player.
 */

public class pblock {

	private int x,y; // Position
	private int dx; // Movement speed and dir.
	private int width; // Player width
  private int height; // Player height
	private boolean visible; // Basically am I alive.
	private ArrayList pShots; // An array of shots.
	
	
	public pblock() {
		x = 200; // Set initial position
		dx = 0; // Set initial velocity (0)
		y = 240; // set initial position. 240 is near the bottom of the screen.
		width = 60; 
		height = 30;
		visible = true; // I am alive at first I hope
		pShots = new ArrayList(); // Create an array. 
	}
	
  // Move the player by adding dx to its current position.
  // If dx < 0 move left, dx>0 move right. 
	public void move() {
		x += dx;
		
		if (x < 1) // Don't let the player leave the screen to the left...
			x = 1;   // But what about the right?
	}
	
  // Get properties of the class. 
	public int getX() {
		return x;
	}
	
	public int getY() {
		return y;
	}
	
	public int getWidth() {
		return width;
	}
	
	public int getHeight() {
		return height;
	}
	
	public boolean isVisible() {
		return visible;
	}
	
	public ArrayList getPshots() {
		return pShots;
	}
	
	public void setVisible(boolean v) {
		visible = v;
	}
	
   
  /*
   * The key inputs from TAdapter in the Main.java class
   * get sent here to these methods. 
   * Notice that these methods don't call on move(), that's the
   * job of the Main.java class.
   */
	public void KeyPressed( KeyEvent e) {
		
		int key = e.getKeyCode();
		
		if (key == KeyEvent.VK_LEFT) // Arrow key left, change movement velocity.
			dx = 1;
		if (key == KeyEvent.VK_RIGHT) // Arrow key right, " "
			dx = -1;
		if (key == KeyEvent.VK_X)
			fire();
	}
	
  // Add a new shot to our shot array. The "+25" makes it
  // look like it fired from the middle of the player. 
	public void fire() {
		pShots.add(new pShot(x + 25, y));
	}
	
  // When the keys are released, change the velocity to 0. 
	public void KeyReleased(KeyEvent e) {
		int key = e.getKeyCode();
		
		if (key == KeyEvent.VK_LEFT)
			dx = 0;
		if (key == KeyEvent.VK_RIGHT)
			dx = 0;
	}
	
  // Get player bounds for collisions. 
	public Rectangle getBounds() {
		return new Rectangle(x, y, width, height);
	}
	
	
	
}
